package com.qf.main.login.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.main.login.common.vo.SysPermissionVo;
import com.qf.main.login.entity.SysPermission;
import com.qf.main.login.mapper.SysPermissionMapper;
import com.qf.main.login.service.PermissionService;
import com.qf.main.login.utils.CommonBeanutils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chengqiang
 * @Create 2024-01-19-19:17
 * @Description:
 */
@Service("permissionService")
public class PermissionServiceImpl implements PermissionService {
    @Resource
    public SysPermissionMapper sysPermissionMapper;

    @Override
    public List<SysPermissionVo> queryPermissionList(int permissionId) {
        QueryWrapper<SysPermission> qw  = new QueryWrapper<>();
        qw.eq(SysPermission.COL_PARENT_ID,permissionId);
        List<SysPermission> sysPermissionList = sysPermissionMapper.selectList(qw);
        List<SysPermissionVo> sysPermissionVoList = CommonBeanutils.convertListTo(sysPermissionList, SysPermissionVo::new);
        for (SysPermissionVo sysPermissionVo : sysPermissionVoList) {
            sysPermissionVo.setSonPermissionList(queryPermissionList(sysPermissionVo.getId()));
        }

        return sysPermissionVoList;
    }
    @Override
    public List<SysPermissionVo> queryPermissionList() {
        QueryWrapper<SysPermission> qw  = new QueryWrapper<>();
        qw.eq(SysPermission.COL_PARENT_ID,0);
        List<SysPermission> sysPermissionList = sysPermissionMapper.selectList(qw);
        List<SysPermissionVo> sysPermissionVoList = CommonBeanutils.convertListTo(sysPermissionList, SysPermissionVo::new);
        for (SysPermissionVo sysPermissionVo : sysPermissionVoList) {
            sysPermissionVo.setSonPermissionList(queryPermissionList(sysPermissionVo.getId()));
        }

        return sysPermissionVoList;
    }


}
